var vo={};
$(function(){
	var openWindow=window.document;
	var searchHeight=$("#divform").height();
	$("#listHistory").height($(openWindow).height()-$(openWindow).height()*0.05-searchHeight);
	$("#listHistory").datagrid({
					url:'/counthistory/getHistory',
					title:'历史统计列表',
					method:'get',
					pagination:true,
					singleSelect:true,
					view: detailview,
					pageList: window.PageSize,
					loadMsg:'加载中......',
					nowrap:true,
					columns:[[
							 {field:'dealerid',title:'经销商编号', align:'left',width:100,sortable:true},
					         {field:'dealername',title:'经销商名称', align:'left',width:100},
					         {field:'cmonth',title:'统计月份', align:'left',width:80},
					         {field:'counttotal',title:'统计金额', align:'left',width:100},
					         {field:'stand',title:'合格数量', align:'left',width:100},
					         {field:'unstand',title:'不合格数量', align:'left',width:100},
					     ]],
					     detailFormatter:function(index,row){
					            return '<div style="padding:2px"><table id="dayview' + index + '"></table></div>';
			                },
	                onExpandRow:function(index,row){
				    	 var dealerid=row.dealerid;
				    	 var cmonth=row.cmonth;
				    	 $("#dayview"+index).datagrid({
				    		 	url:'/counthistory/getSub',
				    		 	queryParams:{'dealerid':dealerid,'cmonth':cmonth},
								title:'门店统计',
								method:'get',
								pagination:true,
								pageList: window.subPageSize,
								loadMsg:'加载中......',
							    columns:[[
							              	 {field:'shopid',title:'门店编号', align:'left',width:100,sortable:true},
							              	 {field:'shopname',title:'门店名称', align:'left',width:100,sortable:true},
									         {field:'counttotal',title:'金额',align:'left',width:60},
									         {field:'stand',title:'合格数据',align:'left',width:60,formatter:function(value,row,index){
													if(value==''||value==undefined){
														return 0;
													}
													return value;
											 }},
									         {field:'unstand',title:'不合格数据',align:'left',width:80,formatter:function(value,row,index){
													if(value==''||value==undefined){
														return 0;
													}
													return value;
											 }},
											 {field:'startdate',title:'开始时间',align:'left',width:80,formatter:function(value,row,index){
												 if(value==''||value==undefined){
									        		 return '';
									        	 }
									        	 var datetime=Common.formatterDate(value);
									        	 return datetime;
											 }},
											 {field:'enddate',title:'结束时间',align:'left',width:80,formatter:function(value,row,index){
												 if(value==''||value==undefined){
									        		 return '';
									        	 }
									        	 var datetime=Common.formatterDate(value);
									        	 return datetime;
											 }}
									     ]],
							    onResize:function(){  
							    	$('#listHistory').datagrid('fixDetailRowHeight',index);  
					             },
				                onLoadSuccess:function(){  
				                    setTimeout(function(){  
				                    	$('#listHistory').datagrid('fixDetailRowHeight',index);  
				                    },0);  
				                },
				    	 });
				    	 $('#listHistory').datagrid('fixDetailRowHeight',index);
				     }
				});
	var codelength=$('#cmonth').width();
	$('#cmonth').validatebox({
	    validType: 'month',
	    tipPosition:'top',
	    deltaX:codelength/4
	});
	$("#serbutton").click(function(){
		vo.dealerid=$("#dealerid").val();
		vo.dealername=$("#dealername").val();
		vo.cmonth=$("#cmonth").val();
		$("#listHistory").datagrid('load',vo);
	});
});
/**
 * 导出为excel
 */
function exportXls(){
	vo.isback=getVal(vo.isback);
	vo.dealerid=getVal(vo.dealerid);
	vo.dealername=getVal(vo.dealername);
	vo.backbegintime=getVal(vo.backbegintime);
	vo.backendtime=getVal(vo.backendtime);
	vo.countbegintime=getVal(vo.countbegintime);
	vo.countendtime=getVal(vo.countendtime);
	var url='/backinfo/exportXls?isback='+vo.isback+'&dealerid='+vo.dealerid+'&dealername='+
	vo.dealername+'&backbegintime='+vo.backbegintime+'&backendtime='+vo.backendtime+'&countbegintime='+vo.countbegintime+'&countendtime='+vo.countendtime;
	window.open(url,'','',false);
}
